﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuaInterface;
using UnityEngine;

namespace GMBase.Lua
{
    /// <summary>
    /// lua文件管理。
    /// 编辑状态加载、跨平台打包加载、assetbundle动态加载，全都在这里处理。
    /// </summary>
    class LuaFileMgr : SingletonAuto<LuaFileMgr>
    {
        public const string LuaExternName = ".lua";

        public bool bUseAssetBundle = false; // 强制使用AssetBundle
        public bool bUseResource = false;

        /// <summary>
        /// 处理平台
        /// </summary>
        public void Init()
        {
            if (bUseAssetBundle)
            {
                LoadLuaFromAssetBundle();
                return;
            }
            if (bUseResource)
            {
                LoadLuaFromResource();
                return;
            }

            if (Application.platform == RuntimePlatform.WindowsEditor)
            {
                LoadLuaFromEditor();
            }
            else if (Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.Android)
            {
                LoadLuaFromResource();
            }
        }

        private void LoadLuaFromResource()
        {
            new LuaLoaderForResource();
        }
        private void LoadLuaFromAssetBundle()
        {
            new LuaLoaderForAssetBundle();
        }
        private void LoadLuaFromEditor()
        {
            new LuaLoaderForEditor();
        }
    }
}